import requests
import json  # 导入 json 模块
import pandas as pd  # 导入 pandas 模块

# 获取人口数据
with open("data/wb_population.json") as f:
    lreg = json.load(f)

# 提取经济体名称、代码和人口数量
nm_pop = [d["country"]["value"] for d in lreg[1]]
cd_pop = [d["countryiso3code"] for d in lreg[1]]
pop_values = [d["value"] for d in lreg[1]]

# 创建 DataFrame 并保存为 CSV
df_pop = pd.DataFrame({"name": nm_pop, "id": cd_pop, "population": pop_values})
df_pop.to_csv("data/wb_population.csv", index=False)